package komorki;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;



public class Neighbours {
	private ArrayList<Komorka> nei = new ArrayList<Komorka>();
	static private ManagerKomorek man = ManagerKomorek.getManager();
	
	
	public static void changeManager(ManagerKomorek m){
		man = m;
	}
	public void add(int row, int column){
		if(check(row, column)){
			nei.add(man.getKomorka(row, column));
		}
	}
	
	private boolean check(int row, int column){
		if(row < 0 || column < 0 || row >= ManagerKomorek.maxRow || column >= ManagerKomorek.maxColumn)
			return false;

		return true;
	}
	
	
	
	public HashMap<Color,Integer> map(){
		HashMap<Color, Integer> mapa = new HashMap<Color, Integer>();
		Integer val;
		
		for(Komorka kom : nei){
				val = mapa.get(kom.getColor());
				if(val == null){
					val = new Integer(1);
				}
				else{
					val++;
				}
				mapa.put(kom.getColor(), val);
		}
		return mapa;
	}
	
	public Iterator<Komorka> iterator(){
		return nei.iterator();
	}
	

}
